package com.daguchuangyi.erp_android.production_detail.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.constraint.ConstraintLayout;
import android.util.AttributeSet;
import android.widget.TextView;

import com.daguchuangyi.erp_android.R;
import com.daguchuangyi.erp_android.model.product.Parameter;

/**
 * Created by lijianjian on 2018/3/11.
 */

public class ProductDetailSectionView extends ConstraintLayout {
    private String mTitleStr;
    private String mContentStr;

    private TextView mTitleTv;
    private TextView mContentTv;

    public ProductDetailSectionView(Context context) {
        this(context, null);
    }

    public ProductDetailSectionView(Context context, AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public ProductDetailSectionView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        if (attrs != null) {
            TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ProductDetailSectionView);
            mTitleStr = ta.getString(R.styleable.ProductDetailSectionView_pds_section_title);
            mContentStr = ta.getString(R.styleable.ProductDetailSectionView_pds_section_content);
            ta.recycle();
        }

        inflate(context, R.layout.view_product_detail_layout, this);
        mTitleTv = (TextView) findViewById(R.id.title_tv);
        mContentTv = (TextView) findViewById(R.id.content_tv);

        mTitleTv.setText(mTitleStr);
        mContentTv.setText(mContentStr);
        if (isInEditMode()) {
            mTitleTv.setText("标题");
            mContentTv.setText("内容内容区域");
        }
    }

    public void bindParameter(Parameter parameter) {
        mTitleTv.setText(parameter.getName());
        mContentTv.setText(parameter.getProductparameters().getValue());
    }

    public void bindContent(String titleStr, String value) {
        mTitleTv.setText(titleStr);
        mContentTv.setText(value);
    }
}
